package com.ai.bitcoin.controller;

import com.ai.bitcoin.util.IdGeneration;
import com.tianru.bitcoin.search.api.domain.BoomBust;
import com.tianru.bitcoin.search.api.domain.BuyerSellerPoint;
import com.tianru.bitcoin.search.api.domain.City;
import com.tianru.bitcoin.search.api.domain.ErcTwoZero;
import com.tianru.bitcoin.search.api.service.BoomBustService;
import com.tianru.bitcoin.search.api.service.BuyerSellerPointService;
import com.tianru.bitcoin.search.api.service.CityService;
import com.tianru.bitcoin.search.api.service.ErcTwoZeroService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: ${description}
 * @author: gulj
 * @create: 2018-08-09 00:42
 **/
@RestController
@Slf4j
public class EsTestController {

    @Autowired
    private CityService cityService;

    @Autowired
    private ErcTwoZeroService esErcTwoZeroService;

    @Autowired
    private BuyerSellerPointService buyerSellerPointService;

    @Autowired
    private BoomBustService boomBustService;

    @GetMapping("/dubbo/test")
    public void esTest() {
        List<City> description = cityService.findByDescription("中国");
        log.info("=={}", description);

        System.out.println(description);
    }

    @GetMapping("/dubbo/save")
    public ErcTwoZero saveErcTwoZero() {

        List<ErcTwoZero> txHash = esErcTwoZeroService.findTxHash("2147483648");
        if (txHash != null && !txHash.isEmpty()) {
            return txHash.get(0);
        }

        ErcTwoZero ercTwoZero = new ErcTwoZero();
        ercTwoZero.setId(Long.valueOf(IdGeneration.getUniqueSign()));
        ercTwoZero.setBccId("1");
        ercTwoZero.setToName("张三");
        ercTwoZero.setVolume("234324.23");
        ercTwoZero.setFromName("李四");
        ercTwoZero.setToAddress("toaddress");
        ercTwoZero.setFromAddress("from address");
        ercTwoZero.setTokenContactAddress("contact address");
        ercTwoZero.setTxHash("2147483648");
        ercTwoZero.setTransferTime("241421421");
        String dd = esErcTwoZeroService.saveEsErcTwoZero(ercTwoZero);

        System.out.println("long id is : " + dd);

        return null;
    }


    @GetMapping("/saveBuyer")
    public Long saveBuyer() {
        BuyerSellerPoint buyerSellerPoint = new BuyerSellerPoint();
        buyerSellerPoint.setId(1L);
        buyerSellerPoint.setCurrentRate("20");
        buyerSellerPoint.setKeyWord("keyword");
        return buyerSellerPointService.save(buyerSellerPoint);
    }

    @GetMapping("/saveBoomBust")
    public Long saveBoomBust() {
        BoomBust boomBust = new BoomBust();
        boomBust.setId(Long.valueOf(IdGeneration.getUniqueSign()));
        boomBust.setKey_word("fdafdasf");
        boomBust.setMarket("ddd");
        boomBust.setPair("pari");
        boomBust.setPrice("dfafs");

        Long save = boomBustService.save(boomBust);
        System.out.println(save);

        return save;
    }

    @GetMapping("/findyBoomBust")
    public BoomBust findyBoomBust(@RequestParam("id") Long id) {
        return boomBustService.findById(id);
    }
}
